import { createSlice } from "@reduxjs/toolkit";

// 定义初始状态值
const initialState = {
  count: 0,  // 默认值
  price: 10.5,
  sum: 0
};

const counterSilce = createSlice({
  name: 'counter', 
  initialState, 
  reducers: { 
    increment(state, { payload }) {
      state.count += payload
      state.sum = state.count * state.price
    },
    decrement(state) {
      state.count -= 1
    }
  }
})

export const { increment, decrement } = counterSilce.actions
export default counterSilce.reducer